package com.wanxi.controller;

import com.wanxi.entity.FacilityClassifyEntity;
import com.wanxi.entity.FacilityDetailsEntity;
import com.wanxi.entity.PageClassifyEntity;
import com.wanxi.service.FacilityClassifyService;
import com.wanxi.service.PageClassifyService;
import com.wanxi.service.impl.FacilityClassifyServiceImpl;
import com.wanxi.service.impl.FacilityDetailsServiceImpl;
import com.wanxi.service.impl.PageClassifyServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * product_center:产品中心
 * @Author : 林子淳
 * @create 2023/2/21 10:10
 */
@WebServlet("/product_center")
public class ProductCenterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1）处理乱码
        req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        //2）得到前端数据
        //3）封装到model（实体类JavaBean）
        //4）调用逻辑层处理逻辑关系,将获得的数据通过JSON以对象的形式传到前端页面;
        //导航栏
        PageClassifyService pageClassifyService = new PageClassifyServiceImpl();
        //医疗设备
        FacilityClassifyService facilityClassifyService = new FacilityClassifyServiceImpl();
        //设备详情
        FacilityDetailsServiceImpl facilityDetailsService = new FacilityDetailsServiceImpl();
        //5）处理完后，得到结果
        //导航栏
        List<PageClassifyEntity> pageList = pageClassifyService.selectServic();
        req.setAttribute("pageList",pageList);
        //医疗设备
        List<FacilityClassifyEntity> facilityList = facilityClassifyService.selectServic();
        req.setAttribute("facilityList",facilityList);
        //设备详情
        List<FacilityDetailsEntity> facilityDetailsList = facilityDetailsService.selectServic();
        req.setAttribute("facilityDetailsList",facilityDetailsList);
        //6）返回给前端：页面转发
        req.getRequestDispatcher("/jsp/product.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
